package com.example.h9iserver.service.springAi.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

import static org.springframework.ai.vectorstore.pgvector.PgVectorStore.PgDistanceType.COSINE_DISTANCE;
import static org.springframework.ai.vectorstore.pgvector.PgVectorStore.PgIndexType.HNSW;

@Configuration
public class VectorStoreConfig {

    @Resource
    private DocumentLoader documentLoader;

    @Resource
    private VectorStore vectorStore;

    @Resource
    private MyTokenTextSplitter myTokenTextSplitter;

//    @Bean
    VectorStore getVectorStore(EmbeddingModel embeddingModel) {
        // 加载文档
        List<Document> documents = documentLoader.loadMarkdowns();
        List<Document> documentsSplitCustomized = myTokenTextSplitter.splitCustomized(documents);
        vectorStore.add(documentsSplitCustomized);
        return vectorStore;
    }
}